package com.xizi.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.xizi.utils.RabbitUtils;
import org.junit.Test;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Provider1 {
    //生成消息
    @Test
    public void testSendMessage() throws IOException, TimeoutException {

        //获取连接对象
        Connection connection = RabbitUtils.getConnection();
        //获取连接的通道
        Channel channel = connection.createChannel();
        //通道绑定对应消息队列
        channel.queueDeclare("work",true,false,false,null );

        //发布消息
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            String next = sc.next();
            channel.basicPublish("", "work", null, next.getBytes());
            System.out.println("【发送消息完成: 】"+next);
        }
        //关闭通道,连接
//        RabbitUtils.ColseConnectionAndChanel(connection,channel );
    }
}
